package com.zy.explore.db.infrastructure.enums;

/**
 * 建类说明：数据库类型枚举
 *
 * @author 中国印
 * @date 2022年02月17日 02:20:33
 */
public enum DatabaseEnum {
    /**
     * ORACLE数据库
     */
    ORACLE(1, "oracle.jdbc.OracleDriver", "SELECT 1 FROM DUAL", "jdbc:oracle:thin:@{}:{}:{}"),
    /**
     * sqlServer数据库
     */
    SQL_SERVER(2, "com.microsoft.sqlserver.jdbc.SQLServerDriver", "SELECT 1", "jdbc:sqlserver://{}:{};DatabaseName={}"),
    /**
     * mysql数据库
     */
    MYSQL(3, "com.mysql.cj.jdbc.Driver", "SELECT 1 FROM DUAL", "jdbc:mysql://{}:{}/{}?serverTimezone=GMT%2B8&useUnicode=true&charaterEncoding=utf-8&useSSL=false"),
    /**
     * DB2数据库
     */
    DB2(4, "com.ibm.db2.jcc.DB2Driver", "SELECT 1 FROM SYSIBM.SYSDUMMY1", "jdbc:db2://{}:{}/{}");

    DatabaseEnum(int type, String driverClassName, String validationQuery, String url) {
        this.type = type;
        this.driverClassName = driverClassName;
        this.validationQuery = validationQuery;
        this.url = url;
    }

    public static DatabaseEnum getDatabase(int type) {
        for (DatabaseEnum dataBase : values()) {
            if (type == dataBase.type) {
                return dataBase;
            }
        }
        return MYSQL;
    }

    /**
     * 数据库类型
     */
    private final int type;
    /**
     * 驱动类
     */
    private final String driverClassName;
    /**
     * 校验连接sql
     */
    private final String validationQuery;
    /**
     * 连接url
     */
    private final String url;

    public int getType() {
        return type;
    }

    public String getDriverClassName() {
        return driverClassName;
    }

    public String getValidationQuery() {
        return validationQuery;
    }

    public String getUrl() {
        return url;
    }
}
